/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fait.ferm.ui;

import fait.ferm.datafx.TableViewFactory;
import fait.ferm.global.Glob;
import fait.ferm.persists.Credit;
import fait.ferm.persists.Directory;
import fait.ferm.persists.Equipment_breakdown;
import fait.ferm.persists.Plan_details_equipment;
import fait.ferm.persists.Plan_details_pay_credit;
import fait.ferm.persists.SimpleDirItem;
import fait.ferm.ui.tables.CreditPayRow;
import fait.ferm.ui.tables.EquipmentPayRow;
import fait.ferm.ui.tables.FeedPersonalRow;
import fait.ferm.ui.tables.ResourcePayRow;
import fait.ferm.ui.tables.SalaryPayRow;
import fait.ferm.ui.tables.TaxesPayRow;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;

/**
 *
 * @author alex
 */
public class PlanTabPayPaneController implements Initializable {
	@FXML 
	private StackPane taxesSP;
	@FXML 
	private StackPane resSP;
	@FXML 
	private StackPane salarySP;
	@FXML 
	private StackPane equipSP;
	@FXML 
	private StackPane creditSP;
//	@FXML
	private TableView<TaxesPayRow> taxesTable;
//	@FXML
	private TableView<SalaryPayRow> salaryTable;
//	@FXML
	private TableView<CreditPayRow> creditTable;
//	@FXML
	private TableView<EquipmentPayRow> equipTable;
//	@FXML
	private TableView<ResourcePayRow> resTable;

	@FXML 
	private Label subtotal;
	@FXML 
	private HBox stHbox;


	@Override
	public void initialize(URL url, ResourceBundle rb) {
		fillTaxesPay();
		fillSalaryPay();
		fillEquipPay();
		fillCreditPay();
		fillResourcePay();
		stHbox.setStyle("-fx-background-color: linear-gradient(to bottom, #efefef 0%, #bfbfbf 100%);-fx-border-width: 1px 0 0 0;-fx-border-color: #006299;");
		subtotal.setText("34426.0");
		
	}

	public void fillTaxesPay(){
		Directory d = Glob.getDirInCache("taxes_type");
		ObservableList<TaxesPayRow> persItems = FXCollections.observableArrayList();
		// TODO заполнить настоящими данными
		persItems.add(new TaxesPayRow(d.get(1), 233.0, new Date(),false));
		persItems.add(new TaxesPayRow(d.get(2), 33.0, new Date(),false));
		persItems.add(new TaxesPayRow(d.get(1), 30.0, new Date(),false));

		taxesTable = TableViewFactory.create(TaxesPayRow.class, persItems).buildTableView();
		taxesSP.getChildren().add(taxesTable);
		
	}
	public void fillSalaryPay(){
		SimpleDirItem d = new SimpleDirItem(-1, "Заработная плата","");
		ObservableList<SalaryPayRow> persItems = FXCollections.observableArrayList();
		// TODO заполнить настоящими данными		
		persItems.add(new SalaryPayRow(d, 14300.0, new Date(),false));
		persItems.add(new SalaryPayRow(d, 12400.0, new Date(),false));
		persItems.add(new SalaryPayRow(d, 2440.0, new Date(),false));

		salaryTable = TableViewFactory.create(SalaryPayRow.class, persItems).buildTableView();
		salarySP.getChildren().add(salaryTable);
		
	}
	public void fillEquipPay(){
		SimpleDirItem d = new SimpleDirItem(-1, "На оборудование","");
		ObservableList<EquipmentPayRow> persItems = FXCollections.observableArrayList();
        ArrayList<Plan_details_equipment> al = (ArrayList<Plan_details_equipment>)Glob.getPlan().getPlan_details_equipment().obj;
        for(Plan_details_equipment cur_eq: al) {
            
            persItems.add(new EquipmentPayRow(d, cur_eq.price, cur_eq.date_performed,false));
            
        }

		equipTable = TableViewFactory.create(EquipmentPayRow.class, persItems).buildTableView();
		equipSP.getChildren().add(equipTable);
		
	}
	public void fillCreditPay(){
        ArrayList<Plan_details_pay_credit> al = (ArrayList<Plan_details_pay_credit>)Glob.getPlan().getPlan_details_pay_credit().obj;
        ObservableList<CreditPayRow> persItems = FXCollections.observableArrayList();
        for(Plan_details_pay_credit cur_pay: al) {
            System.out.println(cur_pay.credit_id + " " + cur_pay.price);
            
            try {
                Credit cur_credit = new Credit(cur_pay.credit_id);
                SimpleDirItem d = new SimpleDirItem(-1, Glob.getDirInCache("credit_type").get(cur_credit.credit_type_id) + " от " + cur_credit.date_beg.toString() + " на сумму " + cur_credit.amount_given,"");
                persItems.add(new CreditPayRow(d, cur_pay.price, cur_pay.date_performed,false));
            } catch(Exception ex) {
                Logger.getLogger(PlanTabPayPaneController.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }

		creditTable = TableViewFactory.create(CreditPayRow.class, persItems).buildTableView();
		creditSP.getChildren().add(creditTable);
		
	}
	public void fillResourcePay(){
		Directory d = Glob.getDirInCache("resource_type");
		ObservableList<ResourcePayRow> persItems = FXCollections.observableArrayList();
		// TODO заполнить настоящими данными		
		persItems.add(new ResourcePayRow(d.get(1), 1200.0, new Date(),false));
		persItems.add(new ResourcePayRow(d.get(2), 1188.0, new Date(),false));
		persItems.add(new ResourcePayRow(d.get(1), 400.0, new Date(),false));

		resTable = TableViewFactory.create(ResourcePayRow.class, persItems).buildTableView();
		resSP.getChildren().add(resTable);
		
	}
	
}
